﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MyVoteMVC.BackstageManagement.Controllers;
using MyVoteMVC.Domain;

namespace MyVoteMVC.BackstageManagement.Views
{
    public partial class AddQuestion : Form, IQuestionView
    {
        public event EventHandler OnAddComplete;

        private IQuestionController controller;

        private string activityId;
        
        public AddQuestion(string activityId)
        {
            InitializeComponent();
            controller = new QuestionController(this);
            this.activityId = activityId;
           
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            controller.CreateQuestion(
                activityId,
                txtTitle.Text,
                txtContent.Text,
               (cbMultiItems.Checked ? (numMutilCount.Value == 0 ? 1 : (int)numMutilCount.Value) : 1),
                cbMustAnswer.Checked ? 1 : 0,
                cbMultiItems.Checked ? 1 : 0);
        }

        void Clear()
        {
            txtContent.Text = "";
            txtTitle.Text = "";
            //cbMultiItems.Checked = false;
            cbMustAnswer.Checked = false;
            numMutilCount.Value = 0;
           
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
          
        }

        private void AddActivity_FormClosing(object sender, FormClosingEventArgs e)
        {
            OnAddComplete(null, null);
        }

        public void CreateQuestionComplete(string message)
        {
            MessageBox.Show(message);
            Clear();
        }

        public void EditQuestionComplete(string message)
        {
            throw new NotImplementedException();
        }

        public void GetQuestionComplete(VT_Questions question)
        {
            throw new NotImplementedException();
        }

        private void cbMultiItems_CheckedChanged(object sender, EventArgs e)
        {
            pMutilCount.Visible = cbMultiItems.Checked;
        }

        public void OnSubmitError(string message)
        {
            MessageBox.Show(message);
        }

        private void AddQuestion_Load(object sender, EventArgs e)
        {
            numMutilCount.Maximum = int.MaxValue;
        }
    }
}
